<% design_pull_in_progress = @environment.ciState == 'manifest_locked'
   open_manifest_release = @manifest && @manifest.releaseState == 'open'
   design_latest = @manifest && @manifest.parentReleaseId == @catalog.releaseId %>
<div class="marker"><%= design_latest ? status_marker('design', 'latest', 'label') : status_marker('design', 'pull', 'label-info') %></div>
<div class="description">
  <ul class="status-items">
    <% if design_latest %>
      <li>
        <%= icon('magnet') %> Latest design release
        <strong><%= link_to(@catalog.releaseId, redirect_release_path(@catalog.releaseId)) %></strong>
        <% if @design_pull_releasse %>
          pulled <strong><%= time_ago_in_words(@design_pull_releasse.created_timestamp) %></strong>
        <% end %>
      </li>
    <% else %>
      <li>
        <%= icon('magnet') %> New design release
        <strong><%= link_to(@catalog.releaseId, redirect_release_path(@catalog.releaseId)) %></strong>
        available since <strong><%= time_ago_in_words(@catalog.updated_timestamp) %></strong>
      </li>
    <% end %>

    <li><%= icon('user') %> Design committed by <strong><%= @catalog.createdBy %></strong></li>
    <% if @catalog.description.present? %>
      <li><%= icon('comment') %><%= @catalog.description %></li>
    <% end %>

    <% if open_manifest_release || design_pull_in_progress %>
      <li>
        <%= icon('info-circle') %>Design pull is <b>disabled</b>
        <% if open_manifest_release %>
          until current release is committed
        <% else %>
          while pull is already in progress
        <% end %>
      </li>
    <% end %>

    <% if design_pull_in_progress %>
      <li id="design_pull_in_progress"><%= render 'design_pull_in_progress' %></li>
    <% end %>

    <% comments     = @environment.comments
       error_prefix = 'ERROR:MANIFEST:' %>
    <% if comments.present? && comments.start_with?(error_prefix) %>
      <li><%= content_tag(:div, comments.sub(/^#{error_prefix}/, ''), :class => 'alert alert-danger') %></li>
    <% end %>
  </ul>
  <% if has_transition?(@assembly.ciId) %>
    <ul class="status-actions">
      <li>
        <% if open_manifest_release || design_pull_in_progress %>
          <% if design_latest %>
            <%= button('Force Pull', nil, 'inverse disabled') %>
          <% else %>
            <%= button('Pull Design', nil, 'info disabled') %>
          <% end %>
        <% else %>
          <%= link_confirm_busy(design_latest ? button('Force Pull', nil, 'inverse') : button('Pull Design', nil, 'info'),
                                :url     => pull_assembly_transition_environment_path(@assembly, @environment, :async => true),
                                :method  => :post,
                                :confirm => 'Pull latest design?',
                                :busy    => 'Initiating latest design pull ...') %>
        <% end %>
      </li>
    </ul>
  <% end %>
</div>
